﻿using Microsoft.VisualStudio.TestTools.UnitTesting;

using MultiLanguage;
using MultiLanguage.Infrastructure;

using System;
using System.Globalization;

namespace UnitTests
{
    [TestClass]
    public class ModelTests
    {
        [TestMethod, Description("Test Fahrenheit")]
        public void TestFarenheit()
        {
            ITemperatureConverter converter = new TemperatureConverter();
            double celsius = converter.ToCelsius(32);
            Assert.IsTrue(AcceptableTolerance(celsius, 0));
        }
        [TestMethod, Description("Test Celsius")]
        public void TestCelsius()
        {
            ITemperatureConverter converter = new TemperatureConverter();
            double farhenheit = converter.ToFahrenheit(100);
            Assert.IsTrue(AcceptableTolerance(farhenheit, 212));
        }
        [TestMethod, Description("Test extremes")]
        public void TestExtremes()
        {
            ITemperatureConverter converter = new TemperatureConverter();
            double farhenheit = converter.ToFahrenheit(Double.MaxValue);
            Assert.IsTrue(Double.IsInfinity(farhenheit));
            double celsius = converter.ToCelsius(Double.MaxValue);
            Assert.IsFalse(Double.IsNaN(celsius));
            farhenheit = converter.ToFahrenheit(-Double.MaxValue);
            Assert.IsTrue(Double.IsInfinity(farhenheit));
            celsius = converter.ToCelsius(-Double.MaxValue);
            Assert.IsFalse(Double.IsNaN(celsius));
            farhenheit = converter.ToFahrenheit(Double.Epsilon);
            Assert.IsTrue(AcceptableTolerance(farhenheit, 32));
            celsius = converter.ToCelsius(Double.Epsilon);
            Assert.IsTrue(AcceptableTolerance(celsius, -17.777777777));
        }
        [TestMethod, Description("Test the format provider")]
        public void TestFormatProvider()
        {
            ISupportedCultureInfo supportedCultureInfo = new SupportedCultureInfo(new CultureInfo("fr-FR"), null);
            double number = 123.00;
            var fmt = number.ToString("N", supportedCultureInfo.FormatProvider);
            Assert.IsTrue(fmt.Contains(","));
        }
        private bool AcceptableTolerance(double anyNumber, double exactValue)
        {
            return Math.Abs(anyNumber - exactValue) < 1e-6;
        }
    }
}
